import { ref } from "vue"
import service from "@/axios"

export default function useMatchVo() {
    const matchVo = ref({
        matchId: "",
        startDate: "",
        itemName: "",
        title: "",
        homeName: "",
        awayName: "",
        homeScore: "",
        awayScore: "",
        winner: "",
        userId: "",
        name: "",
        score: "",
        win: "",
    });

    let matchVos = ref([]);
    let MatchVosByUser = ref([]);
    let MatchVosByMatch = ref([]);

    async function getAllMatchVo() {
        try {
            const response = await service.get("/matchVos");
            matchVos.value = response.data.data;
        } catch (error) {
            console.error(error);
        }
    }

    async function getWinMatchVoByUser(userId) {
        try {
            const response = await service.get(`/matchVosByUserId?userId=${userId}`);
            MatchVosByUser.value = response.data.data;
        } catch (error) {
            console.error(error);
        }
    }

    async function getWinMatchVoByMatch(matchId) {
        try {
            const response = await service.get(`/matchVosByMatchId?matchId=${matchId}`);
            MatchVosByMatch.value = response.data.data;
        } catch (error) {
            console.error(error);
        }
    }

    return {
        matchVo,
        matchVos,
        MatchVosByUser,
        MatchVosByMatch,
        getAllMatchVo,
        getWinMatchVoByUser,
        getWinMatchVoByMatch
    }
}